//
//  ADVideoAlertVC.swift
//  YongQingFont
//
//  Created by 李东 on 2024/7/19.
//

import UIKit

class ADVideoAlertVC: UIViewController {
    
    @IBOutlet weak var adBtn2: UIButton!
    @IBOutlet weak var adBtn3: UIButton!
    
    @IBOutlet weak var hintLabel: UILabel!
    @IBOutlet weak var btnView: UIView!
    
    @IBOutlet weak var btnView_height: NSLayoutConstraint!
    @IBOutlet weak var hintLabel_top: NSLayoutConstraint!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = UIColor.black.withAlphaComponent(0.5)
        btnView_height.constant = 0
        btnView.isHidden = true
        hintLabel_top.constant = 0
        adHelper.finishVideoCallBack = {[weak self] in
            ADUtils.shared.updateAdTimes()
            if ADUtils.shared.finishTask {
                self?.dismiss(animated: true)
                return
            }
            self?.reloadUI()
        }
        reloadUI()
    }
    
    func reloadUI() {
        if ADUtils.shared.times == 0 {
            return
        }
        btnView.isHidden = false
        hintLabel_top.constant = 20
        btnView_height.constant = 63
        if ADUtils.shared.times == 2 {
            adBtn2.isEnabled = false
        }
    }
    
    lazy var adHelper: NewADTools = {
        return NewADTools()
    }()


    @IBAction func closeHandle(_ sender: Any) {
        dismiss(animated: true)
    }
    
    @IBAction func startLoadAd(_ sender: Any) {
        adHelper.loadAD(type: .REWARD_VIDEO, vc: self)
    }
    
    @IBAction func adBtnHandle(_ sender: Any) {
        adHelper.loadAD(type: .REWARD_VIDEO, vc: self)
    }
}
